package com.wilmer.videoOrder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wilmer.videoOrder.domain.dto.VideoOrderDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.videoOrder.domain.VideoOrder;
import com.wilmer.videoOrder.service.IVideoOrderService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 视频订单Controller
 * 
 * @author jett
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/video_order/order")
public class VideoOrderController extends BaseController
{
    @Autowired
    private IVideoOrderService videoOrderService;

    /**
     * 查询视频订单列表
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoOrder videoOrder)
    {
        startPage();
        List<VideoOrder> list = videoOrderService.selectVideoOrderList(videoOrder);
        return getDataTable(list);
    }

    /**
     * 导出视频订单列表
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:export')")
    @Log(title = "视频订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoOrder videoOrder)
    {
        List<VideoOrder> list = videoOrderService.selectVideoOrderList(videoOrder);
        ExcelUtil<VideoOrder> util = new ExcelUtil<VideoOrder>(VideoOrder.class);
        util.exportExcel(response, list, "视频订单数据");
    }

    /**
     * 获取视频订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(videoOrderService.selectVideoOrderById(id));
    }

    /**
     * 新增视频订单
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:add')")
    @Log(title = "视频订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoOrder videoOrder)
    {
        return toAjax(videoOrderService.insertVideoOrder(videoOrder));
    }

    /**
     * 修改视频订单
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:edit')")
    @Log(title = "视频订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoOrder videoOrder)
    {
        return toAjax(videoOrderService.updateVideoOrder(videoOrder));
    }

    /**
     * 删除视频订单
     */
    @PreAuthorize("@ss.hasPermi('video_order:order:remove')")
    @Log(title = "视频订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(videoOrderService.deleteVideoOrderByIds(ids));
    }

    /**
     * 视频下单（小程序）
     */
    @Log(title = "App视频下单", businessType = BusinessType.INSERT)
    @PostMapping("/createVideoOrder")
    public AjaxResult createVideoOrder(@RequestBody VideoOrderDto dto)
    {
        return success(videoOrderService.createVideoOrder(dto));
    }
}
